package user.internet;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import base.Constant;
import user.bean.Company_info_bean;

/**
 * Created by wangic on 2017/2/9.
 */
public class GetCompanyInfo_utils {
    private static final String TAG = "GetCompanyInfo_utils";

    public void GetCompanyInfo(final Handler handler) {
        RequestParams requestParams = new RequestParams(Constant.getCompanyInfo_url);
        x.http().get(requestParams, new Callback.CommonCallback<JSONObject>() {
            @Override
            public void onSuccess(JSONObject result) {
                Log.e(TAG, "onSuccess: "+result.toString());
                try {
                    if (result.get("status").toString().equals("100")) {
                        JSONObject data = (JSONObject) result.get("data");
                        Company_info_bean companyInfo = new Company_info_bean();
                        companyInfo.setColor((String) data.get("color"));
                        companyInfo.setBanner((String) data.get("banner"));
                        Message message = new Message();
                        message.what = 5;
                        message.obj = companyInfo;
                        handler.sendMessage(message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                Message msg = new Message();
                msg.what = Constant.ERROR_MSG;
                handler.sendMessage(msg);

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }
}
